home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / Local / Audio / CSoundChannel.as < prev    next >
Encoding:
Text File  |  2011-08-19  |  7.5 KB  |  306 lines

  1.  
  2. {
  3.    if(true)
  4.    {
  5.       CSoundChannel = ┬º┬ºnewclass(CSoundChannel,EventDispatcher);
  6.    }
  7. }
  8.  
  9. package Local.Audio
  10. {
  11.    import Local.*;
  12.    import flash.display.*;
  13.    import flash.events.*;
  14.    import flash.filters.*;
  15.    import flash.geom.*;
  16.    import flash.media.*;
  17.    import flash.utils.getTimer;
  18.    
  19.    public class CSoundChannel extends EventDispatcher
  20.    {
  21.       
  22.       public static const CLOSING:String = "CLOSING";
  23.       
  24.       public static const mMixVolumeMax:Number = 1;
  25.       
  26.       public static const DISPOSING:String = "DISPOSING";
  27.       
  28.       public static const mDisturbTime:int = 1000 / 50;
  29.        
  30.       
  31.       private var mSoundChannel:SoundChannel;
  32.       
  33.       public var mSounds:Object;
  34.       
  35.       private var mNewSound:Boolean;
  36.       
  37.       private var mResumeStartPosition:int;
  38.       
  39.       public var mPauseTimeStamp:uint;
  40.       
  41.       public var mDisposed:Boolean;
  42.       
  43.       public var _StartTimeStamp:uint;
  44.       
  45.       private var mSample:CSample;
  46.       
  47.       public function CSoundChannel()
  48.       {
  49.          super();
  50.          mSounds = new Array();
  51.       }
  52.       
  53.       public function set mStartTimeStamp(param1:uint) : void
  54.       {
  55.          var _loc2_:CSound = null;
  56.          if(true)
  57.          {
  58.             _StartTimeStamp = param1;
  59.          }
  60.          for each(_loc2_ in mSounds)
  61.          {
  62.             _loc2_.mTimeStamp = _StartTimeStamp;
  63.          }
  64.       }
  65.       
  66.       public function RemoveSound(param1:CSound) : void
  67.       {
  68.          param1.removeEventListener(CSound.DISPOSING,e_SOUND_DISPOSING);
  69.          mSounds.splice(mSounds.indexOf(param1),1);
  70.          param1.Dispose();
  71.          param1.mChannel = null;
  72.          if(mSounds.length == 0)
  73.          {
  74.             Dispose();
  75.          }
  76.       }
  77.       
  78.       public function AddSound(param1:CSound) : void
  79.       {
  80.          if(true)
  81.          {
  82.             mSounds.push(param1);
  83.             if(true)
  84.             {
  85.                if(!mSample)
  86.                {
  87.                   if(true)
  88.                   {
  89.                      mSample = param1.mSample;
  90.                      addr31:
  91.                      mNewSound = true;
  92.                   }
  93.                   param1.mChannel = this;
  94.                   param1.addEventListener(CSound.DISPOSING,e_SOUND_DISPOSING);
  95.                   addr49:
  96.                   return;
  97.                   addr37:
  98.                }
  99.                ┬º┬ºgoto(addr31);
  100.             }
  101.             ┬º┬ºgoto(addr37);
  102.          }
  103.          ┬º┬ºgoto(addr49);
  104.       }
  105.       
  106.       public function get mStartTimeStamp() : uint
  107.       {
  108.          return _StartTimeStamp;
  109.       }
  110.       
  111.       public function get mSampleID() : String
  112.       {
  113.          ┬º┬ºpush(mSample);
  114.          if(true)
  115.          {
  116.             return !!┬º┬ºpop() ? mSample.mID : "none";
  117.          }
  118.          ┬º┬ºgoto(addr14);
  119.       }
  120.       
  121.       public function Start() : Boolean
  122.       {
  123.          mStartTimeStamp = getTimer();
  124.          mNewSound = false;
  125.          if(mSoundChannel = mSample.Start(mSoundTransform))
  126.          {
  127.             mSoundChannel.addEventListener(Event.SOUND_COMPLETE,e_SOUNDCOMPLETE);
  128.          }
  129.          ┬º┬ºpush(mSoundChannel == null);
  130.          if(true)
  131.          {
  132.             ┬º┬ºpush(!┬º┬ºpop());
  133.          }
  134.          return ┬º┬ºpop();
  135.       }
  136.       
  137.       public function Pause() : void
  138.       {
  139.          var _loc1_:CSound = null;
  140.          mResumeStartPosition = mSoundChannel.position;
  141.          mPauseTimeStamp = getTimer();
  142.          Stop();
  143.          for each(_loc1_ in mSounds)
  144.          {
  145.             _loc1_.Pause();
  146.          }
  147.       }
  148.       
  149.       private function e_SOUND_DISPOSING(param1:Event = null) : void
  150.       {
  151.          var _loc2_:CSound = null;
  152.          _loc2_ = CSound(param1.currentTarget);
  153.          RemoveSound(_loc2_);
  154.       }
  155.       
  156.       public function Resume() : void
  157.       {
  158.          var _loc1_:CSound = null;
  159.          for each(_loc1_ in mSounds)
  160.          {
  161.             if(true)
  162.             {
  163.                _loc1_.Resume();
  164.             }
  165.          }
  166.          if(true)
  167.          {
  168.             _StartTimeStamp += getTimer() - mPauseTimeStamp;
  169.             if(true)
  170.             {
  171.                if(mSoundChannel = mSample.Start(mSoundTransform,mResumeStartPosition))
  172.                {
  173.                   mSoundChannel.addEventListener(Event.SOUND_COMPLETE,e_SOUNDCOMPLETE);
  174.                }
  175.             }
  176.             Update();
  177.          }
  178.       }
  179.       
  180.       private function get mSoundsUpdated() : Boolean
  181.       {
  182.          if(true)
  183.          {
  184.             return !mSample.mLooping && mNewSound;
  185.          }
  186.          ┬º┬ºgoto(addr17);
  187.       }
  188.       
  189.       public function Restart() : void
  190.       {
  191.          if(true)
  192.          {
  193.             Stop();
  194.             Start();
  195.          }
  196.       }
  197.       
  198.       public function Update() : void
  199.       {
  200.          var _loc1_:CSound = null;
  201.          for each(_loc1_ in mSounds.slice())
  202.          {
  203.             _loc1_.Update();
  204.          }
  205.          if(mDisposed)
  206.          {
  207.             return;
  208.          }
  209.          if(mSoundChannel)
  210.          {
  211.             if(mSoundChannel.position > mDisturbTime && mSoundsUpdated)
  212.             {
  213.                Restart();
  214.             }
  215.             else
  216.             {
  217.                mSoundChannel.soundTransform = mSoundTransform;
  218.             }
  219.          }
  220.          else
  221.          {
  222.             Start();
  223.          }
  224.       }
  225.       
  226.       private function Stop() : void
  227.       {
  228.          if(mSoundChannel)
  229.          {
  230.             mSoundChannel.stop();
  231.             mSoundChannel.removeEventListener(Event.SOUND_COMPLETE,e_SOUNDCOMPLETE);
  232.             mSoundChannel = null;
  233.          }
  234.       }
  235.       
  236.       private function e_SOUNDCOMPLETE(param1:Event = null) : void
  237.       {
  238.          if(true)
  239.          {
  240.             dispatchEvent(new Event(CLOSING));
  241.             Dispose();
  242.          }
  243.       }
  244.       
  245.       public function get mSoundTransform() : SoundTransform
  246.       {
  247.          var _loc1_:Number = NaN;
  248.          var _loc2_:Number = NaN;
  249.          var _loc3_:Number = NaN;
  250.          var _loc4_:Number = NaN;
  251.          var _loc5_:CSound = null;
  252.          var _loc6_:SoundTransform = null;
  253.          if(!CGlobal.mSoundActive)
  254.          {
  255.             return new SoundTransform(0,0);
  256.          }
  257.          _loc1_ = 0;
  258.          _loc2_ = 0;
  259.          _loc3_ = 0;
  260.          _loc4_ = 0;
  261.          for each(_loc5_ in mSounds)
  262.          {
  263.             if(true)
  264.             {
  265.                _loc3_ += _loc5_.mSoundTransform.leftToLeft;
  266.                if(true)
  267.                {
  268.                   _loc4_ += _loc5_.mSoundTransform.rightToRight;
  269.                   if(_loc5_.mSoundTransform.volume <= _loc2_)
  270.                   {
  271.                      continue;
  272.                   }
  273.                }
  274.                _loc2_ = _loc5_.mSoundTransform.volume;
  275.             }
  276.          }
  277.          if(true)
  278.          {
  279.             (_loc6_ = !!mSoundChannel ? mSoundChannel.soundTransform : new SoundTransform()).volume = _loc2_;
  280.             if(true)
  281.             {
  282.                _loc6_.leftToLeft = _loc3_ / mSounds.length;
  283.                _loc6_.rightToRight = _loc4_ / mSounds.length;
  284.             }
  285.             return _loc6_;
  286.          }
  287.          ┬º┬ºgoto(addr98);
  288.       }
  289.       
  290.       public function Dispose() : void
  291.       {
  292.          var _loc1_:CSound = null;
  293.          dispatchEvent(new Event(DISPOSING));
  294.          Stop();
  295.          for each(_loc1_ in mSounds)
  296.          {
  297.             _loc1_.mChannel = null;
  298.          }
  299.          if(true)
  300.          {
  301.             mDisposed = true;
  302.          }
  303.       }
  304.    }
  305. }
  306.